package com.joehaivo.hweather.View;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SearchView;

import com.joehaivo.hweather.R;

public class AddCityActivity extends AppCompatActivity {
    SearchView searchCityView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_city);
        searchCityView = (SearchView)findViewById(R.id.searchCitySV);

        searchCityView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                Intent intent = new Intent();
                //把返回数据存入Intent
                intent.putExtra("result", query);
                //设置返回数据
                AddCityActivity.this.setResult(RESULT_OK, intent);
                //关闭Activity
                AddCityActivity.this.finish();
                return false;
            }

            @Override
            public boolean onQueryTextChange(String query) {
//                Cursor cursor = TextUtils.isEmpty(s) ? null : queryData(s);
//                // 不要频繁创建适配器，如果适配器已经存在，则只需要更新适配器中的cursor对象即可。
//                if (searchCityView.getSuggestionsAdapter() == null) {
//
//                    searchCityView.setSuggestionsAdapter(new CursorAdapter(AddCityActivity.this, android.R.layout.simple_list_item_1, cursor, new String[]{"name"}, new int[]{R.id.text1}));
//                } else {
//                    mSearchView.getSuggestionsAdapter().changeCursor(cursor);
//                }

                return false;
            }
        });
    }
}
